/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.oea.struts.forms;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Sony
 */
public class FacultyRegisterForm extends org.apache.struts.action.ActionForm {
    
    private  String fname,lname,mname,gender,email,password,contact;
    private Long addedby,id;
   private boolean status;

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }
   
//
//    public boolean isStatu() {
//        return statu;
//    }
//
//    public void setStatu(boolean statu) {
//        this.statu = statu;
//    }

//    private boolean statu;
//
//    public boolean isStatu() {
//        return statu;
//    }
//
//    public void setStatu(boolean statu) {
//        this.statu = statu;
//    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getAddedby() {
        return addedby;
    }

    public void setAddedby(Long addedby) {
        this.addedby = addedby;
    }
   
    
    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getMname() {
        return mname;
    }

    public void setMname(String mname) {
        this.mname = mname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

  

    

    
   
    public FacultyRegisterForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        
         Pattern contact_regex = Pattern.compile("[7-9][0-9]{9}");
        Matcher contact_matcher = contact_regex.matcher(getContact());
        
        Pattern fname_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher fname_matcher = fname_regex.matcher(getFname());
       
        Pattern mname_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher mname_matcher = mname_regex.matcher(getMname());
        
        Pattern lname_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher lname_matcher = lname_regex.matcher(getLname());
        
        if (getFname() == null || getFname().length() < 1) {
            errors.add("fname",new ActionMessage("faculty-register-error-fname-required"));
        }
       
        if (!fname_matcher.matches()) {
             errors.add("fname", new ActionMessage("faculty-register-error-fname-valid"));
        }
        
        if (getMname() == null || getMname().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("mname", new ActionMessage("faculty-register-error-mname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (!mname_matcher.matches()) {
             errors.add("mname", new ActionMessage("faculty-register-error-mname-valid"));
        }
        if (getLname() == null || getLname().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("lname", new ActionMessage("faculty-register-error-lname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (!lname_matcher.matches()) {
             errors.add("lname", new ActionMessage("faculty-register-error-lname-valid"));
        }
        if (getGender() == null || getGender().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("gender", new ActionMessage("faculty-register-error-gender-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getEmail() == null || getEmail().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("email", new ActionMessage("faculty-register-error-email-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getPassword() == null || getPassword().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("password", new ActionMessage("faculty-register-error-password-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        
        if (getContact() == null || getContact().length() != 10) {
            // System.out.println(" Error Avi bhai");
            errors.add("contact", new ActionMessage("faculty-register-error-contact-required"));
            // TODO: add 'error.name.required' key to your resources
        }
          if (!contact_matcher.matches()) {
             errors.add("contact", new ActionMessage("faculty-register-error-contact-valid"));

        }
        return errors;
    }
}
